package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author yanglei
 * @Description: 高级公海模式 - 客户退回规则子分类
 * @date 222/4/19 15:24
 */
@Getter
public enum ClueSeniorBackChildEnum {
    /**
     * 无新建跟进
     */
    CLUE_NO_COMMUNICATE(1, "enum.clueSeniorBackChildEnum.name.clue_no_communicate"),
    /**
     * 未转换客户
     */
    CLUE_NO_TRANSFORM_CUSTOMER(2, "enum.clueSeniorBackChildEnum.name.clue_no_transform_customer"),
    /**
     * 客户未捞取或分配
     */
    CLUE_NO_GAIN_DISTRIBUTION(3, "enum.customerSeniorBackChildEnum.name.clue_no_gain_distribution"),
    /**
     * 未知规则,当异常时用于返回
     */
    UNKNOWN(404, "enum.clueSeniorBackChildEnum.name.unknown");

    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;


    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code  枚举值
     * @param name  枚举名
     */
    ClueSeniorBackChildEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }


    /**
     * 获取全部枚举
     *
     * @return List<PublicCustomerRuleEnum>
     */
    public static List<ClueSeniorBackChildEnum> getAllEnum() {
        List<ClueSeniorBackChildEnum> list = new ArrayList<>();
        for (ClueSeniorBackChildEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    public static ClueSeniorBackChildEnum getEnumByCode(Integer code) {
        for (ClueSeniorBackChildEnum cache : values()) {
            if (Objects.equals(code,cache.getCode())){
                return cache;
            }
        }
        return UNKNOWN;
    }

    public static String getNameByCode(Integer code) {
        for (ClueSeniorBackChildEnum cache : values()) {
            if (Objects.equals(code,cache.getCode())){
                return cache.getName();
            }
        }
        return "";
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
